package com.zhw.utils;


import com.zhw.enums.CodeEnum;

/**
 * Created by 廖师兄
 * 2017-07-16 18:36
 */
public class EnumUtil {    //根据枚举类型返回枚举信息

    /*
    * <T extends CodeEnum> T ：<T extends CodeEnum>是对T的说明
    * Class<T> enumClass：可能是支付或者订单枚举，用T抽象化
    * */
    public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass) {
        for (T each: enumClass.getEnumConstants()) {
            if (code.equals(each.getCode())) {
                return each;
            }
        }
        return null;
    }
}
